home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C04 / StackTest.cpp < prev   
Encoding:
C/C++ Source or Header  |  2000-05-25  |  864 b   |  34 lines

  1. //: C04:StackTest.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. //{L} Nested
  7. //{T} NestTest.cpp
  8. // Test of nested linked list
  9. #include "Stack.h"
  10. #include "../require.h"
  11. #include <fstream>
  12. #include <iostream>
  13. #include <string>
  14. using namespace std;
  15.  
  16. int main(int argc, char* argv[]) {
  17.   requireArgs(argc, 1); // File name is argument
  18.   ifstream in(argv[1]);
  19.   assure(in, argv[1]);
  20.   Stack textlines;
  21.   textlines.initialize();
  22.   string line;
  23.   // Read file and store lines in the Stack:
  24.   while(getline(in, line))
  25.     textlines.push(new string(line));
  26.   // Pop the lines from the Stack and print them:
  27.   string* s;
  28.   while((s = (string*)textlines.pop()) != 0) {
  29.     cout << *s << endl;
  30.     delete s; 
  31.   }
  32.   textlines.cleanup();
  33. } ///:~
  34.